using System;

namespace RobotRules
{
    /// <summary>
    /// The exception that is thrown when a robot control file cannot be downloaded due to
    /// a transfer problem (not just an HTTP status code indicating failure).
    /// </summary>
    [Serializable]
    public class DownloadFailedException : RobotException
    {
// ReSharper disable InconsistentNaming
        private const string DEFAULT_MESSAGE = "The download failed.";
// ReSharper restore InconsistentNaming
        
#pragma warning disable 1591
        public Uri Address { get; private set; }
        
        public override string Message
        {
            get { return base.Message + Environment.NewLine + Address; }
        }

        public DownloadFailedException() : base(DEFAULT_MESSAGE)
        {
            Address = null;
        }

        public DownloadFailedException(Uri address) : base(DEFAULT_MESSAGE)
        {
            Address = address;
        }

        public DownloadFailedException(Uri address, Exception inner)
            : base(DEFAULT_MESSAGE, inner)
        {
            Address = address;
        }

        public DownloadFailedException(string message, Uri address) : base(message)
        {
            Address = address;
        }

        public DownloadFailedException(string message, Uri address, Exception inner) : base(message, inner)
        {
            Address = address;
        }

#pragma warning restore 1591
        /// <summary>
        /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception.
        /// </summary>
        /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown. </param><param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination. </param><exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (Nothing in Visual Basic). </exception><filterpriority>2</filterpriority><PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/></PermissionSet>
        public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            Address = info.GetValue("Address", typeof (Uri)) as Uri;
            base.GetObjectData(info, context);
        }
    }
}